<% title "Groups informations in service: #{ServiceInformation.where(:serviceId=>@group_information_item).where(:service_information_table_id=>1).first.name}" %>
<% logger.debug "@group_information_item: #{@group_information_item}"%>
<% query = GroupInformationTable.find_by_sql("\
			SELECT group_informations.title,group_informations.group_type, COUNT(episode_ofs.crid) as episodes \
			FROM episode_ofs, program_informations, schedule_events, schedules, service_informations, group_informations \
			WHERE schedule_events.schedule_id=schedules.id AND schedule_events.programCrid=program_informations.crid \
			AND schedule_events.programCrid=program_informations.crid AND program_informations.id=episode_ofs.program_information_id \
			AND service_informations.serviceId=schedules.service_id\
			AND program_informations.program_information_table_id=1 AND schedules.program_location_table_id=1 \
			AND group_informations.group_information_table_id=1 AND service_informations.service_information_table_id=1\
			AND group_informations.groupId=episode_ofs.crid AND group_informations.group_type='series' \
			AND service_informations.serviceId=#{@group_information_item} GROUP BY group_informations.groupId\
			")
%>

<table class='tabla'>
  <tr class='modo1'>
    <th>#</th>
    <th>Group title</th>
    <th>Episodes</th>
    <th>Type</th>
  </tr>
  <% index=0 %>
  <% for item in query %>
   <tr class='modo2'>
      <td><%= index = index +1 %></td>
      <td><%= item['title'] %></td>
      <td><%= item['episodes'] %></td>
      <td><%= item['group_type'] %></td>
    </tr>
  <% end %>
</table>

